//
//  DYJShortTableViewCell.m
//  Piece
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 Northeast Dianli University. All rights reserved.
//

#import "DYJShortTableViewCell.h"

@implementation DYJShortTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 5;
        //短片
        self.shortImageView = [[UIImageView alloc] init];
        self.shortImageView.image = [UIImage imageNamed:@"read_essay"];
        [self.contentView addSubview:_shortImageView];
        
        self.shortTitleLabel = [[UILabel alloc] init];
        self.shortTitleLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_shortTitleLabel];
        //self.shortTitleLabel.numberOfLines = 0;
        self.shortAuthorLabel = [[UILabel alloc] init];
        self.shortAuthorLabel.textColor = [UIColor colorWithRed:0.14 green:0.63 blue:0.91 alpha:1.00];
        self.shortAuthorLabel.font = [UIFont systemFontOfSize:14];
        self.shortAuthorLabel.numberOfLines = 0;
        [self.contentView addSubview:_shortAuthorLabel];
        
        self.shortContentLabel = [[UILabel alloc] init];
        self.shortContentLabel.textColor = [UIColor colorWithRed:0.75 green:0.75 blue:0.75 alpha:1.00];
        self.shortContentLabel.font = [UIFont systemFontOfSize:14];
        self.shortContentLabel.numberOfLines = 0;
        [self.contentView addSubview:_shortContentLabel];
        
        self.shortLineView = [[UIView alloc] init];
        self.shortLineView.backgroundColor = [UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:1.00];
        [self.contentView addSubview:_shortLineView];
    }
    return self;
}
- (void)setShortModel:(DYJShortModel *)shortModel
{
    if (_shortModel != shortModel) {
        _shortModel = shortModel;
        self.shortTitleLabel.text = _shortModel.hp_title;
        self.shortAuthorLabel.text = _shortModel.authorModel.user_name;
        self.shortContentLabel.text = _shortModel.guide_word;
    }
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.shortImageView.frame = CGRectMake(8, 10, 48, 48);
    self.shortTitleLabel.frame = CGRectMake(60, 15, ScreenWidth - 90, 30);
    self.shortAuthorLabel.frame = CGRectMake(self.shortTitleLabel.frame.origin.x, self.shortTitleLabel.frame.origin.y + self.shortTitleLabel.frame.size.height + 3, self.shortTitleLabel.frame.size.width, 20);
    //规定字体的大小样式:
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName,nil];
    //得到新的frame
    CGRect shortRect = [self.shortContentLabel.text boundingRectWithSize:CGSizeMake(self.shortTitleLabel.frame.size.width - 3, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.shortContentLabel.frame = CGRectMake(self.shortTitleLabel.frame.origin.x, self.shortAuthorLabel.frame.origin.y + self.shortAuthorLabel.frame.size.height + 8, shortRect.size.width, shortRect.size.height);
    
    self.shortLineView.frame = CGRectMake(self.shortTitleLabel.frame.origin.x, self.shortContentLabel.frame.origin.y + self.shortContentLabel.frame.size.height + 10, ScreenWidth - 20 - self.shortTitleLabel.frame.origin.x - 20, 1);
}
@end
